//package com.ruoyi.framework.config;
//
//
//import lombok.extern.slf4j.Slf4j;
//import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
//import org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.ApplicationContext;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.env.Environment;
//
///**
// * 配置文件解密核心类
// */
//@Slf4j
//@Configuration
//public class EncryptionConfig {
//
//    String publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAMILUEDi4Q9N+OVTXdHd6qA9aBmhKfAbsJRR6vvhU70pau10Bht7gTH+2EmTF0+u4exvnYFcRKd1uRKuPXTWnXMCAwEAAQ==";
//
//    @Bean
//    public StandardPBEStringEncryptor stringEncryptor(Environment environment) {
//        StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
//        EnvironmentStringPBEConfig config = new EnvironmentStringPBEConfig();
//        // 从配置文件或环境变量中获取加密密码
//        String encryptionPassword = environment.getProperty("jasypt.encryptor.password");
//        config.setAlgorithm("PBEWithMD5AndDES");
//        config.setPassword(encryptionPassword);
//        encryptor.setConfig(config);
//        return encryptor;
//    }
//
//    @Autowired
//    private ApplicationContext applicationContext;
//    private Environment environment;
//
//    public EncryptionConfig() {
//        System.out.println("EncryptionConfig is being initialized.");
//    }
//
//    public EncryptionConfig(Environment environment) {
//        this.environment = environment;
//        if (environment == null) {
//            System.out.println("Environment is null in EncryptionConfig constructor.");
//        }
//    }
//
//    //    @PostConstruct
//    public void checkContext() {
//        if (applicationContext.getBeanDefinitionCount() > 0) {
//            log.info("ApplicationContext has been initialized with " + applicationContext.getBeanDefinitionCount() + " bean definitions.");
//        } else {
//            log.info("ApplicationContext may not be fully initialized.");
//        }
//    }
//
////    @Bean
////    public PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer(StandardPBEStringEncryptor stringEncryptor) {
////        PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer() {
////            @Override
////            protected String convertProperty(String propertyName, String propertyValue) {
////                log.info("Converting property: name={}, value={}", propertyName, propertyValue);
//////                if ("spring.datasource.password".equals(propertyName) && propertyValue.startsWith("ENC(") && propertyValue.endsWith(")")) {
//////                    String encryptedValue = propertyValue.substring(4, propertyValue.length() - 1);
//////                    String decryptedValue = stringEncryptor.decrypt(encryptedValue);
//////                    log.info("Decrypted property: name={}, value={}", propertyName, decryptedValue);
//////                    return decryptedValue;
//////                }
////                return propertyValue;
////            }
////            @Override
////            protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props)
////                    throws BeansException {
////                doProcessProperties(beanFactoryToProcess, null);
////            }
////        };
//////        PropertySourcesPlaceholderConfigurer bean = SpringUtils.getBean(PropertySourcesPlaceholderConfigurer.class);
////
////
////        return configurer;
////    }
//
//}
